package com.rookie.im.domain.resp;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "ApiResult", description = "接口返回结果")
public class ApiResult<T> {
    /**
     * 是否成功
     */
    @ApiModelProperty(value = "是否成功", required = true)
    private boolean success;

    /**
     * 返回码
     */
    @ApiModelProperty(value = "返回码", required = true)
    private Integer code;

    /**
     * 返回信息
     */
    @ApiModelProperty(value = "返回信息")
    private String msg;

    /**
     * 返回数据
     */
    @ApiModelProperty(value = "返回数据")
    private T data;

    public static <T> ApiResult<T> success() {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(true);
        result.setCode(0);
        return result;
    }
    public static <T> ApiResult<T> success(T data) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(true);
        result.setCode(0);
        result.setData(data);
        return result;
    }
    public static <T> ApiResult<T> success(String msg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(true);
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }
    public static <T> ApiResult<T> success(String msg, T data) {
        ApiResult<T> result = new ApiResult<T>();
        result.success = true;
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static <T> ApiResult<T> fail(String msg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(false);
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }
    public static <T> ApiResult<T> fail(int code, String msg) {
        ApiResult<T> result = new ApiResult<T>();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
